$(function () {
    findById();
});

function findById() {
    let id = sessionStorage.getItem("roleId");
    let result = myAjax("/api/rb/role/findById", {id: id}, "post");
    if (result != null) {
        setData(result.data);
    }
}

function setData(data) {
    $("#name").val(data.name),
    $("#code").val(data.code),
    $("#introduce").text(data.introduce),
    $("input[name='status'][value=" + data.status + "]").attr("checked", true);
}

function save() {
    let data = {
        name: $("#name").val(),
        code: $("#code").val(),
        introduce: $("#introduce").val(),
        status: $("input:radio[name='status']:checked").val()
    };
    let result = myAjax("/api/rb/role/add", data, "post");
    if (result.data === "isHave") {
        alert("当前角色名已存在了哟！！！(=^ ^=)")
    } else if (result.code === 200) {
        alert("新增成功！！！(=^ ^=)");
    } else {
        alert("新增失败，请重新输入!!!(=^ ^=)");
    }
}